import 'package:flutter/material.dart';
import 'package:gold/ui/my/shop/order/shop_order_list_page.dart';
import 'package:gold/ui/my/shop/shop_config.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';

/// @description:
/// @author tangzhentao
/// @created at 21:02 2024/12/12

class ShopOrderPage extends StatelessWidget {
  /// 订单状态
  late final ValueNotifier<String> _statusNotifier;

  /// pageView控制器
  late final PageController _controller;

  ShopOrderPage({super.key, required String? orderStatus}) {
    _statusNotifier = ValueNotifier(orderStatus?? '');
    _controller = PageController(initialPage: getShopOrderStatusIndex(orderStatus));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: xfgAppbar(title: '店铺订单'),
      backgroundColor: XfgColor.white,
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(
            height: XfgSize().size52,
            child: ValueListenableBuilder<String?>(
                valueListenable: _statusNotifier,
                builder: (_, select, __) => Row(
                  children: shopOrderStatusList.map((status) {
                    final isSelect = select == status;
                    return Expanded(
                      child: GestureDetector(
                          onTap: () {
                            if (!isSelect) {
                              _statusNotifier.value = status;
                              final index = shopOrderStatusList.indexOf(status);
                              _controller.jumpToPage(index);
                            }
                          },
                          behavior: HitTestBehavior.opaque,
                          child: Padding(
                            padding: EdgeInsets.symmetric(horizontal: XfgSize().size12),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                XfgText(getShopOrderStatusDesc(status), fontSize: XfgSize().text14, color: XfgColor.text1, bold: isSelect ? FontWeight.bold:null),
                                SizedBox(height: XfgSize().size10),
                                Container(height: XfgSize().size3, width: XfgSize().size20, decoration: isSelect ? BoxDecoration(color: XfgColor.theme, borderRadius: BorderRadius.circular(XfgSize().size3)):null),
                                SizedBox(height: XfgSize().size5)
                              ],
                            ),
                          )
                      ),
                    );
                  }).toList(),
                )
            ),
          ),
          Expanded(
            child: Container(
              color: XfgColor.background,
              child: PageView(
                  controller: _controller,
                  onPageChanged: (index) => _statusNotifier.value = shopOrderStatusList[index],
                  children: shopOrderStatusList.map((status) => ShopOrderListPage(orderStatus: status)).toList()
              ),
            ),
          )
        ],
      ),
    );
  }
}

